//
//  PPWebViewViewController.m
//  pickpic
//
//  Created by Jinxiao on 10/6/16.
//  Copyright © 2016 MicroDream. All rights reserved.
//

#import "PPWebViewViewController.h"

@import WebKit;

@interface PPWebViewViewController () <UIWebViewDelegate>
@property (readwrite, nonatomic, strong) WKWebView *webView;
@end

@implementation PPWebViewViewController

- (void)dealloc {
    [_webView stopLoading];
    _webView.scrollView.delegate = nil;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    WKWebViewConfiguration *configuration = [[WKWebViewConfiguration  alloc] init];

    _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0.f, 0, self.view.width, self.view.height) configuration:configuration];
    _webView.scrollView.bounces = NO;
    [self.view addSubview:_webView];

    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_url]]];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    [self.navigationController.view toastMessage:error.networkPrompt];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    return YES;
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}

@end
